# -*- coding: utf-8 -*-
# vim: set noet ts=4:
#
# scim-python
#
# Copyright (c) 2007-2008 Yu Fan <yufanyufan@gmail.com>
#
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA
#
# $Id: $
#

import scim
import os
import traceback
import sys
from gettext import dgettext

from ibus import keysyms
from ibus import modifier
from ibus import ascii
import ibus

from npengine import *
from QuanPin import QuanPinEngine
from PYDict import *
from QuanPin import strip

_ = lambda a : dgettext ("ibus-natural-pinyin", a)

class JianPinEngine(QuanPinEngine):
	def __init__ (self, conn, object_path):
		QuanPinEngine.__init__(self, conn, object_path)

	def split(self, strs):
		if strip(strs) in PINYIN_LIST \
			or strip(strs) in PINYIN_PARTIAL_LIST	\
			or strip(strs) in SHENGMU_LIST \
			or strs == "'":
			yield (strs,  "")
		else:
			for i in range(len(strs), 0, -1):
				if strs[:i][-1] == "'":
					continue
				if strip(strs[:i]) in PINYIN_LIST or strip(strs[:i]) in SHENGMU_LIST:
					yield ( strs[:i], strs[i:] )
					if strip(strs[:i-1]) in PINYIN_LIST and strip(strs[:i])[-1] in SHENGMU_LIST and self.is_valid_head(strs[i-1:]):
						yield ( strs[:i-1], strs[i-1:])
					break
 
